package partFour.homeWork.code.code01;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * 对学生信息的读取，采用ObjectInputStream
 */
public class ReadStuInfo {
    public static void StuInfoRead(){
//        创建ObjectInputStream对象 与"D:/java学习资料/stage-1-module-3/homeWork/代码/Stu/stuInfo.txt" 文件关联
        Object stu = null;
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream("./partFour/homeWork/stuInfo.txt"));
//            从输入流中读取对象并打印。
            stu = ois.readObject();
            System.out.println("--------------------------------------------------------");
            System.out.println("从文件中获取到的学生信息有：\n"+stu);
            System.out.println("--------------------------------------------------------");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (null != ois){
                try {
//                    关闭流对象并释放有关资源！
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
